package weaver.interfaces.expense.action.zcpz;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.expense.ExpenseImp;
import weaver.interfaces.expense.OAExpenseBean;
import weaver.interfaces.util.ExpenseCompare;
import weaver.interfaces.util.ExpenseCompareUtil;
import weaver.interfaces.util.ExpenseInfoUtil;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;
/**
 * 
 * @ClassName: ZCPZ_SJHC_Voucher 
 * @Description:支出凭证-试剂耗损
 * @author xiyufei
 * @date 2017-3-20 上午11:19:21 
 *
 */
public class ZCPZ_SJHC_Voucher  extends BaseBean implements Action{

 
	public String execute(RequestInfo requestInfo) { 
		try {
			String workflowid = requestInfo.getWorkflowid();
			String requestid = requestInfo.getRequestid();
			writeLog("进入ZCPZ_SJHC_Voucher-----------"+requestid);
			RecordSet rs = new RecordSet(); 
			rs.executeSql("select formid from workflow_base where id = " + workflowid);
			rs.next();
			String formid = rs.getString("formid");
			String formtable = "formtable_main_" + formid.replaceAll("-", "");
			 
			String ccode = "";
			double amount = 0;
			String cexpenseitemcode = "";
			String citemcode = "";
			String ly = "";
			String iyear = "";
			//System.out.println("select  id,ks,cexpenseitemcode,citemcode,zje,zjly,sqrq,kth from "+formtable+" where requestid="+requestid);
			rs.execute("select id,ks,zcxm,pjje,ly,sqrq,kth1,liucheng,zf,huansuan from "+formtable+" where requestid="+requestid);
			rs.next(); 
			ExpenseInfoUtil expenseInfoUtil = new ExpenseInfoUtil();
			ccode =  expenseInfoUtil.getKsbm(Util.null2String(rs.getString("ks"))); 
			String cname =  expenseInfoUtil.getCname(ccode); 
			amount =  Util.getDoubleValue(rs.getString("pjje").replace(",", ""),0);

			amount =  Util.getDoubleValue(rs.getString("huansuan").replace(",", ""),0);

			String citemname =  expenseInfoUtil.getCtn(citemcode); 
			cexpenseitemcode=  Util.null2String(rs.getString("zcxm"));  
			String zf =  Util.null2String(rs.getString("zf"));  
	 
			String cexpenseitemname = expenseInfoUtil.getCItemName(cexpenseitemcode); 
			String kth =  Util.null2String(rs.getString("kth1"));  
			ly =  Util.null2String(rs.getString("ly"));  
			iyear =  Util.null2String(rs.getString("sqrq"));
			OAExpenseBean oaExpenseBean= new OAExpenseBean();
			oaExpenseBean.setAmount(amount+"");
			oaExpenseBean.setBilldate(iyear);
			oaExpenseBean.setBilltype("0");
			oaExpenseBean.setCcode(ccode);
			oaExpenseBean.setCname(cname);
			oaExpenseBean.setCexpenseitemcode(cexpenseitemcode);
			oaExpenseBean.setCexpenseitemname(cexpenseitemname);
			oaExpenseBean.setCitemcode(citemcode);
			oaExpenseBean.setCitemname(citemname);
			oaExpenseBean.setLy(ly);
			oaExpenseBean.setZffs(zf);
			oaExpenseBean.setRequestid(requestid);
			ExpenseImp expenseImp = new ExpenseImp();
			expenseImp.insetExpense(oaExpenseBean);
			
		} catch (Exception e) {
			requestInfo.getRequestManager().setMessageid("1111111111");
			requestInfo.getRequestManager().setMessagecontent(e.getMessage()); 
			return FAILURE_AND_CONTINUE;
		}
	
		return SUCCESS;
	}

}
